package tests.update;

import static org.junit.Assert.*;


import java.util.Date;

import model.Budget;
import model.BudgetFactory;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.workplicity.util.Helper;
import org.workplicity.util.WorkDate;
import org.workplicity.worklet.WorkletContext;


public class BudgetUpdateStartDateTest00
{
	Budget budget;
	BudgetFactory factory;

	@Before
	public void setUp() throws Exception
	{
	}

	@After
	public void tearDown() throws Exception
	{
		Helper.delete(budget, WorkletContext.getInstance());
	}

	@SuppressWarnings("deprecation")
	@Test
	public void test()
	{
		factory = new BudgetFactory();

		try
		{
			// Create a budget
			budget = (Budget) factory.create();
			budget.setName("Test budget");
			budget.setDescription("This is an update test budget.");
			budget.commit();

			Date now = new Date();

			now.setMonth(now.getMonth() - 1);
			WorkDate startDate = (WorkDate) now;
			budget.setStartDate(startDate);

			Boolean successful = budget.commit();
			if (!successful)
			{
				fail("Updating Budget failed");
			}

		} catch (Exception e)
		{
			fail("Creating Budget failed with exception: " + e);
		}
	}
}
